home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / circuit.doc < prev    next >
Text File  |  1995-03-31  |  7KB  |  178 lines

  1. (Comp.sys.handhelds) 
  2. Item: 904 by ard at siva.bristol.ac.uk 
  3. Author: [Tony Duell] 
  4.   Subj: HP48 digital logic simulator 
  5.   Date: Mon Oct 15 1990 08:05  
  6.  
  7. Here's a digital circuit simulator for the HP48SX. It has 8 internal 
  8. primatives: AND, OR, XOR, NOT, BUF (buffer), HI (node tied to logic 1), 
  9. LO (node tied to logic 0) and CLK (clock generator of definable high and 
  10. low times). It also supports nested macros defined from these elements. 
  11.  
  12. A circuit is entered as a list of lists. Each sublist defines one gate (or 
  13. macro-circuit) in the design. The format of the sublist is as follows :  
  14. {"NAME" I1 I2 I3..} 
  15. Where NAME is either one of the primatives above or the variable name where the 
  16. macro is stored entered as a string. I1 I2 etc are the names of the nodes in 
  17. your circuit, and must be valid HP48 name objects (or in the case of "CLK", the 
  18. first 2 arguments are integers). For example: 
  19. {"AND" A1 A2 Both}  is the representation of the circuit : 
  20.  
  21.   A1----------!\ 
  22.               ! )--------- Both 
  23.   A2----------!/ 
  24.  
  25.   In the primatives, the inputs are always given first, and I suggest you do 
  26. the same in macros (see below).  
  27.  
  28. 2 - input gates 
  29. --------------- 
  30. There are 3 types of 2-input gate defined, AND, OR and XOR. The formats are 
  31.  
  32.  list format          equivalent expression (which you don't enter) 
  33. {"AND" A1 A2 Q}       Q= A1 AND A2 
  34. {"OR" A1 A2 Q}        Q= A1 OR A2 
  35. {"XOR" A1 A2 Q}       Q= A1 XOR A2 
  36.  
  37. 1 - input gates 
  38. --------------- 
  39.  
  40. There are 2 types of 1-input gate, NOT and Buffer: 
  41.  
  42.  list format        equivalent expression 
  43. {"NOT" A B}         B=NOT A 
  44. {"BUF" A B}         B=A 
  45.  
  46. Tied nodes 
  47. ---------- 
  48. A node can also be defined as permanently high or low :  
  49.  
  50.  list format    equivalent expression 
  51. {"HI" A}        A=1 
  52. {"LO" A}        A=0 
  53.  
  54. Clock Generators. 
  55. The high and low times of the clock generator are defined in terms of 
  56. time-steps which are defined as 1 horizontal pixel on the final timing diagram. 
  57. Note that all gates have a propagation delay of one time-step. The format for 
  58. defining a clock generator is : 
  59. {"CLK" hi_time lo_time Output} 
  60. Where hi_time and lo_time are real numbers giving the number of time-steps that 
  61. the output will be high or low respectively and Output is the node name for the 
  62. output. 
  63. e.g. : 
  64. {"CLK" 4 4 A} defines that node A will be low for 4 time-steps, high for 4 
  65. time-steps, low for 4 time-steps etc. 
  66.  
  67. A circuit is defined by creating a list of these sub-lists e.g.: 
  68. {{"CLK" 2 2 A} {"CLK" 4 4 B} {"AND" A B C}} 
  69.  
  70. The only commands you need to know to run the simulator are as follows: 
  71.  
  72. COMPILE 
  73. ------- 
  74. Takes the variable name where a circuit is stored in top of stack, and sets up 
  75. the internal variables to represent that circuit. Use this before attempting to 
  76. simulate 
  77.  
  78. NODES 
  79. ----- 
  80. Takes a list of nodes which are to appear in the final timing diagram in top of 
  81. stack, and stores it in the internal variable OUT.L 
  82.  
  83. ALL 
  84. --- 
  85. sets up OUT.L to contain _ALL_ nodes in the circuit (including the internal 
  86. ones in macros). Only useful for simple circuits. 
  87.  
  88. SIM 
  89. --- 
  90. Takes a length of simualtion in top of stack (a real number, max 100) and plots 
  91. the timing diagram (in PICT) for the given circuit. After it has finished, 
  92. press any key (except ATTN) to exit and restore the stack display  
  93.  
  94. Example :  
  95. Given the circuit defined above in top of stack, store it in 'CSH' 
  96. then execute the following 
  97. 'CSH' COMPILE            set up this circuit 
  98. ALL                      we'll show all nodes 
  99. 100 SIM                  draw a timing diagram. 
  100.  
  101.  
  102. MACROS 
  103. ------ 
  104. A macro-circuit is a bit like a subroutine - it's a part of a circuit (e.g. a 
  105. half-adder or a flip-flop) which is used several times. For an example, see the 
  106. variable HADD in the directory which contains the macro that defines a half 
  107. adder. 
  108. Each macro definition has the form 
  109. {{External list} {{GATE1}{GATE2}...}} 
  110. where {{GATE1}{GATE2}...} is the circuit description of the macro as defined 
  111. above, and {External list} is the list of external connections. 
  112. e.g. the 2-input multiplexor (variable MUX) in the directory 
  113.  
  114. Circuit  
  115.            !\ 
  116. SEL --+----! >o------------!\ 
  117.       !    !/              ! )--! 
  118.       !             A------!/   ------\----\ 
  119.       !                                )    )-------- Y 
  120.       !             B------!\   ------/----/ 
  121.       !                    ! )--! 
  122.       !--------------------!/ 
  123.  
  124.  
  125. Now, the external connections are SEL, A, B and Y 
  126.  
  127.            !\     NS 
  128. SEL --+----! >o------------!\ 
  129.       !    !/              ! )--! YA 
  130.       !             A------!/   ------\----\ 
  131.       !                                )    )-------- Y 
  132.       !             B------!\   ------/----/ 
  133.       !                    ! )--! YB 
  134.       !--------------------!/ 
  135.  
  136.  
  137. I've now labeled the internal nodes (NS, YA, YB) 
  138.  
  139. Thus, we get the definition: 
  140. {{SEL A B Y}{{"NOT" SEL NS} {"AND" A NS YA} {"AND" B SEL YB} {"OR" YA YB Y}}} 
  141.  
  142. If this is stored in the variable MUX , the element 
  143. {"MUX" X Y Z GO} will be valid, with the correspondence: 
  144. X -> SEL 
  145. Y -> A 
  146. Z -> B 
  147. GO -> Y 
  148.  
  149. circuits (and other macros) can be defined in terms of MUX. 
  150.  
  151.  
  152. Example : the full adder 
  153. ------------------------ 
  154. I have included a simple example to demonstrate the features of this logic 
  155. simulator : the single-bit full adder. 
  156. In the variable HADD is the macro for a half - adder, whereas in FADD, I have 
  157. given the macro for a full-adder, defined in terms of FADD 
  158. In the variable DEMO, I have defined a simple circuit with one full-adder, with 
  159. its 3 input driven from clock-generators in the ratio 1:2:4. Here's how to run 
  160. the demonstration: 
  161. 'DEMO' COMPILE      define the circuit 
  162. {M N P S C} NODES   only display the inputs and outputs 
  163. 100 SIM             display the timing diagram (after it's finished, press any 
  164.                     key to exit) 
  165.  
  166.  
  167. I am quite willing to answer questions about how this program works, but as 
  168. it's likely to be quite long, I'll only post it to the net if there is 
  169. sufficient interest..... 
  170.  
  171. -Tony Duell 
  172. ARD @ UK.AC.BRIS.PVA  (JANET) 
  173. ARD @ SIVA.BRIS.AC.UK (BITNET) 
  174.  
  175. (This program and its documentation are public domain. They may be freely 
  176. copied, used and published in user-group newsletters provided that my name 
  177. remains attached to them. They may not be sold for profit) 
  178.